package org.thinker.web;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;
import org.thinker.service.member.MemberService;
import org.thinker.vo.MemberVO;

@Controller
@RequestMapping("/member")
public class MemberController {
	
	@Resource(name="memberService")
	private MemberService memberService;
	
	@RequestMapping(method=RequestMethod.GET, params="cmd=login")
	public String loginForm()throws Exception{
		return "loginform";
	}
	
	@RequestMapping(method=RequestMethod.POST, params="cmd=login")
	public ModelAndView loginAction(MemberVO vo)throws Exception{
		
		ModelAndView mav = new ModelAndView();
		
		try{
			memberService.loginCheck(vo);
			mav.setViewName("loginSuccess");
			mav.addObject("membervo", vo);
		}catch(Exception e){
			e.printStackTrace();
			mav.setViewName("loginFail");
		}
		return mav;
	}
	
	@RequestMapping(method=RequestMethod.GET, params="cmd=regist")
	public String registForm()throws Exception{
		return "registForm";
	}
	
	@RequestMapping(method=RequestMethod.POST, params="cmd=regist")
	public String registAction(MemberVO vo)throws Exception{
		try{
			memberService.register(vo);
		}catch(Exception e){
			e.printStackTrace();
		}
		return "registAction";
	}

}













